package br.fot.granola.genner.states.blinky;

import android.view.KeyEvent;
import br.fot.granola.oboe.core.Oboe;
import br.fot.granola.oboe.core.Slot;
import br.fot.granola.oboe.graphics.Node;
import br.fot.granola.oboe.util.Vector;


public class Square extends Node 
{
	private Vector speed = new Vector();
	
	public Square() {
		super( new SquareBackend() );
		this.rotation.x = 90;
		((SquareBackend)this.backend).color.set( 1, 0, 0, 1 );
	}
	
	@Slot public void onUpdate()
	{
		this.position.add( this.speed );
		if( this.speed.x != 0 || this.speed.z != 0 ) Oboe.signalUp( this, "onFlyTargetChanged", this.position );
	}
	
	@Slot public void onKeyDown( int code )
	{
		switch( code )
		{
		case KeyEvent.KEYCODE_DPAD_LEFT: speed.x = -1; break;
		case KeyEvent.KEYCODE_DPAD_RIGHT: speed.x = 1; break;
		case KeyEvent.KEYCODE_DPAD_UP: speed.z = -1; break;
		case KeyEvent.KEYCODE_DPAD_DOWN: speed.z = 1; break;
		}
	}
	
	@Slot public void onKeyUp( int code )
	{
		switch( code )
		{
		case KeyEvent.KEYCODE_DPAD_LEFT: speed.x = 0; break;
		case KeyEvent.KEYCODE_DPAD_RIGHT: speed.x = 0; break;
		case KeyEvent.KEYCODE_DPAD_UP: speed.z = 0; break;
		case KeyEvent.KEYCODE_DPAD_DOWN: speed.z = 0; break;
		}
	}
	
	@Slot public void onGetFlyTarget( Vector v )
	{
		v.copy( this.position );
	}
}
